package com.yjt.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.yjt.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 曾智平
 * @ClassName: MyMetaObjectHandler
 * @Description: 重写mybatisplus中的字段填充器  ---mybatisplus起始版本 3.3.0(推荐使用)
 * @date 2021/10/15 16:12
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        //新增时间
        this.strictInsertFill(metaObject, "createTm", LocalDateTime.class, LocalDateTime.now());
        //新增创建人
        this.strictInsertFill(metaObject, "createBy", String.class, SecurityUtils.getCurrentUser().getEmplyId());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        // 更新时间
        this.strictUpdateFill(metaObject, "updateTm", LocalDateTime.class, LocalDateTime.now());
        //新增更新人
        this.strictUpdateFill(metaObject, "updateBy", String.class, SecurityUtils.getCurrentUser().getEmplyId());
    }



}
